//
//  AppDelegate.m
//  吃货·上海
//
//  Created by 濮亚军 on 15/11/23.
//  Copyright © 2015年 濮亚军. All rights reserved.
//

#import "AppDelegate.h"
#import "MainController.h"
#import <BmobSDK/Bmob.h>
#import <ShareSDK/ShareSDK.h>
#import <TencentOpenAPI/QQApiInterface.h>
#import <TencentOpenAPI/TencentOAuth.h>
#import "WXApi.h"
#import "WeiboSDK.h"

#import "StartController.h"
#import "MainController.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    

    // 进入判断启动页面 给本地缓存存入一个BOOL值 来判断是否是第一次进入APP
    BOOL isStart = [[NSUserDefaults standardUserDefaults] boolForKey:@"isStart"];
    if (isStart)
    {
        // nav控制器
        //主控制器
        MainController *mainViewVc = [[MainController alloc]init];
        UINavigationController *mainNav = [[UINavigationController alloc]initWithRootViewController:mainViewVc];
        [[UINavigationBar appearance] setTintColor:[UIColor colorWithRed:40 / 255.0 green:40 / 255.0 blue:40 / 255.0 alpha:1.0]];
        self.window.rootViewController = mainNav;
    }
    else
    {
        StartController *startVc = [[StartController alloc] init];

        self.window.rootViewController = startVc;
    }
    
    //服务器注册
    [Bmob registerWithAppKey:@"86fc9127f3cf4d9fdb234461bac1a6b9"];
    
    
    
//    初始化shareSDK应用
    [ShareSDK registerApp:@"cd9df582bc68"];
    
    //添加新浪微博
//    [ShareSDK connectSinaWeiboWithAppKey:@"1482360090" appSecret:@"8eb9537dbc299bdce11c21caff6e3ce7" redirectUri:@"http://www.sharesdk.cn"];
    //[ShareSDK connectSinaWeiboWithAppKey:@"1482360090" appSecret:@"8eb9537dbc299bdce11c21caff6e3ce7" redirectUri:@"http://www.sharesdk.cn" weiboSDKCls:[WeiboSDK class]];
    
    //添加QQ
    [ShareSDK connectQQWithAppId:@"1104922525" qqApiCls:[QQApiInterface class]];
    
    //添加微信
    [ShareSDK connectWeChatWithAppId:@"wx403a315912cee69e" appSecret:@"d4624c36b6795d1d99dcf0547af5443d" wechatCls:[WXApi class]];
    
    return YES;
}

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    return [ShareSDK handleOpenURL:url wxDelegate:self];
}


- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    return [ShareSDK handleOpenURL:url sourceApplication:sourceApplication annotation:annotation wxDelegate:self];
}

- (void)applicationWillResignActive:(UIApplication *)application {
    

    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
